/**
 * 配件仓库库位维护 编辑页面
 * @author mengyb
 * @date 2019/04/10
 */
define(function () {
    var self,
        app = win.app,
        doc = win.doc,
        vueData = {
            isAdd: false,
            isDetail: false,
            form: '',
            rules: {
                GWAT001: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                GWASL003: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                GWAT002: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWATL004: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWATL005: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWATACTI: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ]
            },
            selectOptions: {
                sys_y_n: app.datas_("sys_y_n")
            }
        },

        // gwasList = [],//配件仓库列表
        callobj,
        layOpenIndex,
        moduleName,
        pageVue
    ;


    var Gwai601Edit = app.Module.extend({

        //初始化
        init: function () {
            self = this;
            self._super({
                _tag: 'gwai601_edit',
                _loadTplsFull: [
                    {
                        dom: 'common_open_window', tpl: 'common/_open_window'
                    }
                ]
            }, win);
        },

        //开窗后回调函数
        _call: function (tagData) {
            pageVue.$refs['form'].resetFields();
            moduleName = tagData.moduleName;
            layOpenIndex = tagData.layOpenIndex;

            if(tagData.is_detail){
                vueData.isDetail = true;
            }else {
                vueData.isDetail = false;
            }

            if (tagData.isAdd) {
                vueData.isAdd = true;
                app.extendUpLow({
                    target: vueData.form,
                    res: {
                        GWAT001: '',
                        GWASL003: '',
                        GWAT002: '',
                        GWATL004: '',
                        GWATL005: '',
                        GWATACTI: 'Y'
                    },
                    reset: true
                });
            } else {
                vueData.isAdd = false;
                callobj = tagData.obj;
                app.extendUpLow({
                    target: vueData.form,
                    res: callobj.data,
                    reset: true
                });
            }
        },

        //新增
        add: function () {
            app.ajax({
                xurl: 'base/gwai601/add',
                xdata: vueData.form,
                loading: true,
                okmsg: moduleName + '信息保存成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule("gwai601").reloadTableCurr();
                        layer.close(layOpenIndex);
                    }

                }
            })
        },

        //修改
        edit: function () {
            app.ajax({
                xurl: 'base/gwai601/edit',
                xdata: vueData.form,
                loading: true,
                okmsg: moduleName + '信息修改成功',
                cb: function (result) {
                    if (result.ok) {
                        callobj.update(result.xdata);
                        layer.close(layOpenIndex);
                    }
                }
            })
        },
        //DOM加载完成后调用
        _ready: function () {
            vueData.form = app.fields_(['base_gwai601']);
            //实例化vue
            pageVue = new Vue({
                el: '#gwai601_edit',
                data: vueData,
                methods: {
                    //关闭窗口
                    cancle: function () {
                        layer.close(layOpenIndex);
                    },
                    //保存
                    save: function () {

                        //表单校验
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                if (vueData.isAdd) {
                                    self.add();
                                } else {
                                    self.edit();
                                }
                            }

                        });

                    },
                    //配件仓库开窗
                    openGwas: function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwas001',
                                    columnList: [
                                        {label: '仓库编号', prop: 'GWAS001', width: '150'},
                                        {label: '说明', prop: 'GWASL003', width: '150'},
                                        {label: '助记码', prop: 'GWASL004', width: '150'}
                                    ]
                                },
                                cb: function (data) {
                                    vueData.form.GWASL003 = data.GWASL003;
                                    vueData.form.GWAT001 = data.GWAS001;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择配件仓库',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    clearGwat001: function () {
                        vueData.form.GWASL003 = '';
                    }
                },

                //使用ElementUI初始化DOM
                created: function () {
                    self._setEleIsReady('gwai601_edit');
                }
            })

        },

        _lazy: function () {
            // app.ajax({
            //     xurl:'base/gwai601/getGwasList',
            //     cb: function (result) {
            //         gwasList=result.data.list;
            //
            //     }
            // })
            this._super();
        }

    });


    return new Gwai601Edit();

});
